package com.wzbc.video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzbc.video.entity.Lesson;
import com.wzbc.video.mapper.LessonMapper;
import com.wzbc.video.req.SearchReq;
import com.wzbc.video.req.UserSearchReq;
import com.wzbc.video.res.LessonRes;
import com.wzbc.video.service.LessonService;
import org.springframework.stereotype.Service;

@Service
public class LessonServiceImpl extends ServiceImpl<LessonMapper, Lesson> implements LessonService {
    @Override
    public Integer insert(Lesson lesson) {
        return this.baseMapper.insert(lesson);
    }

    @Override
    public LessonRes getOneById(Long id) {
        if(id==0L){
            return null;
        }
        return this.baseMapper.getLesson(id);
    }

    @Override
    public IPage<LessonRes> listLesson(SearchReq req) {
        return this.baseMapper.getLessons(new Page<>(req.getPageCurrent(),req.getPageSize()),new QueryWrapper<LessonRes>()
                .eq(req.getId() != null && !req.getId().equals(0L), "lesson.lesson_id", req.getId())
                .eq("lesson.is_show",1)
                .like(req.getName()!=null && !req.getName().isEmpty(),"lesson.lesson_name",req.getName()));
    }
}
